package com.lfs.market.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.lfs.market.model.R;
import com.lfs.market.model.dto.UpdateUserInfoDto;
import com.lfs.market.model.entity.User;
import com.lfs.market.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@SaCheckLogin
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/logout")
    public R logout() {
        StpUtil.logout(StpUtil.getLoginId());
        return R.ok();
    }

    @GetMapping("/getUserInfo")
    public R<User> getUserInfo() {
        return userService.getUserInfo();
    }

    @GetMapping("/getUserInfo/byId")
    public R<User> getUserInfo(String userId) {
        return userService.getUserInfo(userId);
    }

    /**
     *  修改用户信息
     * @param dto
     * @return
     */
    @PutMapping
    public R updateUserInfo(@RequestBody UpdateUserInfoDto dto) {
        userService.updateUserInfo(dto);
        return R.ok();
    }

    /**
     *  修改用户密码
     * @param dto
     * @return
     */
    @PutMapping("/password")
    public R updateUserInfoPass(@RequestBody UpdateUserInfoDto dto) {
        userService.updateUserInfoDetail(dto);
        return R.ok();
    }
}
